//
//  CustTableViewCell.m
//  HappyBug
//
//  Created by liulei on 2018/11/2.
//  Copyright © 2018年 www.hc.com.cn. All rights reserved.
//

#import "CustTableViewCell.h"

#define APP_HEIGHT  [UIScreen mainScreen].bounds.size.height
#define APP_WIDTH  [UIScreen mainScreen].bounds.size.width
@interface CustTableViewCell(){
    
}
@property(nonatomic,strong) UILabel *titltLabel;
@property(nonatomic,strong) UILabel *contentLabel;
@property(nonatomic,strong) UIImageView *leftImage;

@end
@implementation CustTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}
-(void)initView{
    
    _leftImage =[[UIImageView alloc]initWithFrame:CGRectMake(5, 0, 50, 50)];
    _leftImage.backgroundColor=[UIColor clearColor];
    [_leftImage setImage:[UIImage imageNamed:@"img10"]];
    [self addSubview:_leftImage];
    //cell-1
    _titltLabel=[[UILabel alloc]initWithFrame:CGRectMake(_leftImage.frame.size.width+_leftImage.frame.origin.x+5, 0,90, 20)];
    //2
    _titltLabel.text=@"11";
    _titltLabel.font =[UIFont systemFontOfSize:12];
    _titltLabel.textAlignment =NSTextAlignmentLeft;
    [self addSubview:_titltLabel];
    
    _contentLabel=[[UILabel alloc]initWithFrame:CGRectMake(_leftImage.frame.size.width+_leftImage.frame.origin.x+5,_titltLabel.frame.size.height+2,120, 20)];
    _contentLabel.textAlignment =NSTextAlignmentLeft;
    _contentLabel.font =[UIFont systemFontOfSize:9];
    _contentLabel.text=@"11";
    [self addSubview:_contentLabel];
    
    
    
}
//文本cgsize
-(CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *attrs=@{NSFontAttributeName:font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}


//懒加载
//-(UILabel *)titltLabel{
//    //只进行初始化 赋值外部操作
//    if(!_titltLabel){
//        _titltLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 30,APP_WIDTH, 40)];
//        _titltLabel.textAlignment =NSTextAlignmentCenter;
//        [self addSubview:_titltLabel];
//    }
//    return _titltLabel;
//}
//
//-(UILabel *)contentLabel{
//
//}

-(void)setTableCellContentWithDic:(NSMutableDictionary *)dic{
    NSString *titleLabelTxt=   [dic objectForKey:@"titleName"];
    NSString *contentLabelTxt=   [dic objectForKey:@"contentName"];
    NSString *leftImageName=   [dic objectForKey:@"imageName"];
    
    [_leftImage setImage:[UIImage imageNamed:leftImageName]];
    _contentLabel.text=contentLabelTxt;
    _titltLabel.text=titleLabelTxt;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
//    1。使用block 带出去
//    2 代理带出去
    
    if(selected){
        _leftImage.image=[UIImage imageNamed:@"img0"];
        _titltLabel.text=@"我是被点击了";
        _contentLabel.text=@"描述信息真的长我是被点击了";
    }
    
}

@end
